{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Find the Array Concatenation Value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #two-pointers #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #双指针 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: findTheArrayConcVal"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #找出数组的串联值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个下标从 <strong>0</strong> 开始的整数数组&nbsp;<code>nums</code> 。</p>\n",
    "\n",
    "<p>现定义两个数字的 <strong>串联</strong>&nbsp;是由这两个数值串联起来形成的新数字。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如，<code>15</code><span style=\"\">&nbsp;和&nbsp;</span><code>49</code>&nbsp;的串联是&nbsp;<code>1549</code> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p><code>nums</code>&nbsp;的 <strong>串联值</strong>&nbsp;最初等于 <code>0</code> 。执行下述操作直到&nbsp;<code>nums</code>&nbsp;变为空：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>如果&nbsp;<code>nums</code>&nbsp;中存在不止一个数字，分别选中 <code>nums</code> 中的第一个元素和最后一个元素，将二者串联得到的值加到&nbsp;<code>nums</code>&nbsp;的 <strong>串联值</strong> 上，然后从&nbsp;<code>nums</code>&nbsp;中删除第一个和最后一个元素。</li>\n",
    "\t<li>如果仅存在一个元素，则将该元素的值加到&nbsp;<code>nums</code> 的串联值上，然后删除这个元素。</li>\n",
    "</ul>\n",
    "\n",
    "<p>返回执行完所有操作后<em>&nbsp;</em><code>nums</code> 的串联值。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>nums = [7,52,2,4]\n",
    "<b>输出：</b>596\n",
    "<b>解释：</b>在执行任一步操作前，nums 为 [7,52,2,4] ，串联值为 0 。\n",
    " - 在第一步操作中：\n",
    "我们选中第一个元素 7 和最后一个元素 4 。\n",
    "二者的串联是 74 ，将其加到串联值上，所以串联值等于 74 。\n",
    "接着我们从 nums 中移除这两个元素，所以 nums 变为 [52,2] 。\n",
    " - 在第二步操作中： \n",
    "我们选中第一个元素 52 和最后一个元素 2 。 \n",
    "二者的串联是 522 ，将其加到串联值上，所以串联值等于 596 。\n",
    "接着我们从 nums 中移除这两个元素，所以 nums 变为空。\n",
    "由于串联值等于 596 ，所以答案就是 596 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>nums = [5,14,13,8,12]\n",
    "<b>输出：</b>673\n",
    "<b>解释：</b>在执行任一步操作前，nums 为 [5,14,13,8,12] ，串联值为 0 。 \n",
    "- 在第一步操作中： \n",
    "我们选中第一个元素 5 和最后一个元素 12 。 \n",
    "二者的串联是 512 ，将其加到串联值上，所以串联值等于 512 。 \n",
    "接着我们从 nums 中移除这两个元素，所以 nums 变为 [14,13,8] 。\n",
    "- 在第二步操作中：\n",
    "我们选中第一个元素 14 和最后一个元素 8 。\n",
    "二者的串联是 148 ，将其加到串联值上，所以串联值等于 660 。\n",
    "接着我们从 nums 中移除这两个元素，所以 nums 变为 [13] 。 \n",
    "- 在第三步操作中：\n",
    "nums 只有一个元素，所以我们选中 13 并将其加到串联值上，所以串联值等于 673 。\n",
    "接着我们从 nums 中移除这个元素，所以 nums 变为空。 \n",
    "由于串联值等于 673 ，所以答案就是 673 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length &lt;= 1000</code></li>\n",
    "\t<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [find-the-array-concatenation-value](https://leetcode.cn/problems/find-the-array-concatenation-value/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [find-the-array-concatenation-value](https://leetcode.cn/problems/find-the-array-concatenation-value/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[7,52,2,4]', '[5,14,13,8,12]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        left, right = 0, n-1\n",
    "        res = 0\n",
    "        while left <= right:\n",
    "            if left == right:\n",
    "                res += nums[left]\n",
    "            else:\n",
    "                res += nums[left] *(10 ** len(str(nums[right]))) + nums[right]\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        length = len(nums)\n",
    "        for i in range(length):\n",
    "            j = length - i - 1\n",
    "            if i < j:\n",
    "                res = res + nums[i] * 10 ** len(str(nums[j])) + nums[j]\n",
    "            elif i == j:\n",
    "                res = res + nums[i]\n",
    "            else:\n",
    "                break\n",
    "        return res "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        i,j = 0,len(nums)-1\n",
    "        while i<=j:\n",
    "            if i==j:\n",
    "                res += nums[i]\n",
    "            else:\n",
    "                res += int(str(nums[i])+str(nums[j]))\n",
    "            i+=1\n",
    "            j-=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i < j:\n",
    "            cnt = 0\n",
    "            temp = nums[j]\n",
    "            while temp > 0:\n",
    "                cnt += 1\n",
    "                temp //= 10\n",
    "            res += nums[i] * (10 ** cnt) + nums[j]\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        if i == j:\n",
    "            res += nums[i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        i = 0\n",
    "        j = len(nums) - 1\n",
    "        while i < j :\n",
    "            res += int(str(nums[i]) + str(nums[j]))\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        if i == j :\n",
    "            res += nums[i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i <= j:\n",
    "            if i != j:\n",
    "                ans += int(str(nums[i]) + str(nums[j]))\n",
    "            else:\n",
    "                ans += nums[i]\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while len(nums) > 0:\n",
    "            if len(nums) >= 2:\n",
    "                ans += int(str(nums[0]) + str(nums[-1]))\n",
    "                nums = nums[1:len(nums)-1]\n",
    "            elif len(nums) == 1:\n",
    "                ans += nums[0]\n",
    "                nums = []\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        l, r = 0, len(nums) - 1\n",
    "        while l <= r:\n",
    "            if l == r:\n",
    "                res += nums[l]\n",
    "            else:\n",
    "                res += int(str(nums[l]) + str(nums[r]))\n",
    "            l += 1\n",
    "            r -= 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        i, j = 0, len(nums)-1\n",
    "        while i < j:\n",
    "            res += int(str(nums[i])+str(nums[j]))\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        if i == j:\n",
    "            res += nums[i]\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i = 0\n",
    "        j = len(nums) - 1\n",
    "        while i < j: \n",
    "            x = nums[i]\n",
    "            y = nums[j]\n",
    "            while y:\n",
    "                x *= 10\n",
    "                y //= 10\n",
    "            ans += x + nums[j]\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        if i == j:\n",
    "            ans += nums[i]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i <= j:\n",
    "            if i != j:\n",
    "                ans += int(str(nums[i]) + str(nums[j]))\n",
    "            else:\n",
    "                ans += nums[i]\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while len(nums) > 1:\n",
    "            ans += int(str(nums[0])+str(nums[-1]))\n",
    "            del nums[0]\n",
    "            del nums[-1]\n",
    "        return ans if len(nums) == 0 else ans + nums[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        l, r = 0, len(nums)-1\n",
    "        res = 0\n",
    "        while l <= r:\n",
    "            if l < r:\n",
    "                res += int(str(nums[l]) + str(nums[r]))\n",
    "            else:\n",
    "                res += nums[r]\n",
    "            l += 1\n",
    "            r -= 1\n",
    "        return res\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        left,right = 0,len(nums)-1\n",
    "        a = 0\n",
    "        ans=[]\n",
    "        while left<right:\n",
    "            ans.append(int(str(nums[left])+str(nums[right])))\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        return sum(ans)+nums[len(nums)//2] if len(nums)%2!=0 else sum(ans)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        length = len(nums)\n",
    "\n",
    "        ret = 0\n",
    "        for i in range(length // 2):\n",
    "            ret += int('{}{}'.format(nums[i], nums[length - 1 - i]))\n",
    "        \n",
    "        if length & 1:\n",
    "            ret += nums[length // 2]\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while nums:\n",
    "            if len(nums) >= 2:\n",
    "                a,b = nums.pop(0),nums.pop()\n",
    "                ans += int(f\"{a}{b}\")\n",
    "            else:\n",
    "                ans += nums.pop()\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        # 双指针\n",
    "        left,right=0,len(nums)-1\n",
    "        # 记录结果\n",
    "        ans=0\n",
    "        while(left<=right):\n",
    "            if left==right:\n",
    "                ans+=nums[left]\n",
    "            else:\n",
    "                num=str(nums[left])+str(nums[right])\n",
    "                ans+=int(num)\n",
    "            left+=1\n",
    "            right-=1\n",
    "        return ans   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0 \n",
    "        i, j = 0, len(nums) - 1 \n",
    "        while i <= j :\n",
    "            if i == j: \n",
    "                ans += nums[i]\n",
    "            else:\n",
    "                ans += int(str(nums[i]) + str(nums[j]))\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return ans   \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res,n=0,len(nums)\n",
    "        for i in range(n//2):\n",
    "            res+=nums[i]*10**len(str(nums[-1-i]))+nums[-1-i]\n",
    "        if n%2:\n",
    "            res+=nums[n//2]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        l, r = 0, len(nums) - 1\n",
    "        res = \"\"\n",
    "        sub = 0\n",
    "        while l < r:\n",
    "            num1 = nums[l]\n",
    "            num2 = nums[r]\n",
    "            res = num2 + num1 * 10 ** len(str(num2))\n",
    "            l += 1\n",
    "            r -= 1\n",
    "            sub += res\n",
    "            \n",
    "        if l == r:\n",
    "            sub += nums[l]\n",
    "        \n",
    "        return sub"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i <= j:\n",
    "            if i != j:\n",
    "                ans += int(str(nums[i]) + str(nums[j]))\n",
    "            else:\n",
    "                ans += nums[i]\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while(len(nums) != 0):\n",
    "            if len(nums) >= 2:\n",
    "                ans += int(str(nums[0]) + str(nums[len(nums)-1]))\n",
    "                del nums[0]\n",
    "                del nums[len(nums)-1]\n",
    "            else:\n",
    "                ans += nums[0]\n",
    "                del nums[0]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        left = 0\n",
    "        right = len(nums) - 1\n",
    "        ans = 0\n",
    "        while left < right:\n",
    "            n = len(str(nums[right]))\n",
    "            ans += nums[left] * 10 ** n + nums[right]\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        if left == right:\n",
    "            ans += nums[left]\n",
    "        else:\n",
    "            return ans\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        while(len(nums)>0):\n",
    "            if len(nums)>1:\n",
    "                ans+=int(str(nums[0])+str(nums[-1]))\n",
    "                nums.pop(0)\n",
    "                nums.pop()\n",
    "            elif len(nums)==1:\n",
    "                ans+=nums[0]\n",
    "                nums.pop()\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i < j:\n",
    "            ans += int(str(nums[i]) + str(nums[j]))\n",
    "            i, j = i + 1, j - 1\n",
    "        if i == j:\n",
    "            ans += nums[i]\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        e = 0\n",
    "        while len(nums) > 1:\n",
    "            n = int(len(nums)) - 2\n",
    "            a = nums[0]\n",
    "            del nums[0]\n",
    "            b = nums[n]\n",
    "            del nums[n]\n",
    "            a = str(a)\n",
    "            b = str(b)\n",
    "            c = a + b\n",
    "            d = int(c)\n",
    "            e += d\n",
    "        for i in nums:\n",
    "            e += i\n",
    "        return e"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        i,j=0,len(nums)-1\n",
    "        while i<j:\n",
    "            ans+=int(str(nums[i])+str(nums[j]))\n",
    "            i,j=i+1,j-1\n",
    "        if i==j:\n",
    "            ans+=nums[i]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        while nums:\n",
    "            if len(nums) == 1:\n",
    "                res += nums[0]\n",
    "                break\n",
    "            \n",
    "            res += int(str(nums.pop(0))+str(nums.pop()))\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        l=0\n",
    "        n=len(nums)-1\n",
    "        num=0\n",
    "        while n >l:\n",
    "            num += int(str(nums[l])+str(nums[n]))\n",
    "            n=n-1\n",
    "            l=l+1\n",
    "        if n ==l:\n",
    "            num+=nums[n]\n",
    "        return num \n",
    "\n",
    "\n",
    "\n",
    "     "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def add(self, num1, num2):\n",
    "        return int(str(num1) + str(num2))\n",
    "\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        summ = 0\n",
    "\n",
    "        for i in range(n // 2):\n",
    "            summ += int(self.add(nums[i], nums[n - i - 1]))\n",
    "\n",
    "        if n%2==1:\n",
    "            summ += nums[n // 2]\n",
    "\n",
    "        return summ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        while nums:\n",
    "            if len(nums) > 1:\n",
    "                res += int(str(nums.pop(0)) + str(nums.pop(len(nums)-1)))\n",
    "            else:\n",
    "                res += nums.pop(0)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        left = 0\n",
    "        right = len(nums) - 1\n",
    "        ans = 0\n",
    "        while left < right:\n",
    "            n = len(str(nums[right]))\n",
    "            ans += nums[left] * 10 ** n + nums[right]\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        if left == right:\n",
    "            ans += nums[left]\n",
    "        else:\n",
    "            return ans\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        num = 0\n",
    "        while len(nums)>0:\n",
    "            if len(nums)==1:\n",
    "                num+=nums[0]\n",
    "                break\n",
    "            s1 = str(nums[0])\n",
    "            s2 = str(nums[len(nums)-1])\n",
    "            s1+=s2\n",
    "            num+=int(s1)\n",
    "            nums = nums[1:len(nums)-1]\n",
    "        return num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        while len(nums)>1:\n",
    "            chuan=int(str(nums[0])+str(nums[-1]))\n",
    "            ans+=chuan\n",
    "            nums.pop(0)\n",
    "            nums.pop()\n",
    "        if len(nums)==1:\n",
    "            ans+=nums[0]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        n = len(nums)\n",
    "        i,j = 0,n-1\n",
    "        while i<j:\n",
    "            res += int(str(nums[i]) + str(nums[j]))\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        if i == j:\n",
    "            res += nums[i]\n",
    "        \n",
    "        return res\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        l = len(nums)\n",
    "        result = 0\n",
    "        i = 0\n",
    "        j = -1\n",
    "        while l != 0:\n",
    "            if l == 1:\n",
    "                result += nums[i]\n",
    "                l -= 1\n",
    "            else:\n",
    "                result += int(str(nums[i])+str(nums[j]))\n",
    "                i += 1\n",
    "                j -= 1\n",
    "                l -= 2\n",
    "        \n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        res = 0\n",
    "        for i in range(n // 2):\n",
    "            res += int(str(nums[i]) + str(nums[-(i + 1)]))\n",
    "        if n % 2 == 1:\n",
    "            res += nums[n // 2]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        numsum = []\n",
    "        while len(nums) >= 2:\n",
    "            numssum = str(nums.pop(0))+str(nums.pop(-1))\n",
    "            numsum.append(int(numssum))\n",
    "        \n",
    "        if len(nums) % 2 == 0: # 如果序列是偶数，就直接返回，如果序列是奇数，那么列表要将列表里最后剩余的数字拼接起来，输出\n",
    "            return sum(numsum)\n",
    "        else:\n",
    "            numsum += nums\n",
    "            return sum(numsum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        result=0\n",
    "        i,j=0,len(nums)-1\n",
    "\n",
    "        while i<=j:\n",
    "            if i<j:\n",
    "                t=int(str(nums[i])+str(nums[j]))\n",
    "                result+=t\n",
    "            else:\n",
    "                result+=int(nums[i])\n",
    "            i+=1\n",
    "            j-=1\n",
    "        \n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        n = len(nums)\n",
    "        i,j = 0,n-1\n",
    "        while i<j:\n",
    "            res += int(str(nums[i]) + str(nums[j]))\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        if i == j:\n",
    "            res += nums[i]\n",
    "        \n",
    "        return res\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while len(nums)>1:\n",
    "            ans += nums[0]*(10**len(str(nums[-1])))+nums[-1]\n",
    "            del nums[0],nums[-1]\n",
    "        return ans+nums[0] if len(nums)==1 else ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        while len(nums) > 1:\n",
    "            res += int(str(nums[0]) + str(nums[-1]))\n",
    "            nums.pop(-1)\n",
    "            nums.pop(0)\n",
    "        if len(nums) > 0:\n",
    "            res += nums[0]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        while len(nums)>1:\n",
    "            if len(nums)>1:\n",
    "                res += int(str(nums[0])+str(nums[-1]))\n",
    "                nums.pop(0)\n",
    "                nums.pop(-1)\n",
    "        if len(nums)==1:\n",
    "            res+=nums[0]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        i, j = 0, len(nums)-1\n",
    "        ans = 0\n",
    "        while i<=j:\n",
    "            if i==j:\n",
    "                ans += nums[i]\n",
    "            else:\n",
    "                ans += nums[j] + pow(10, int(log10(nums[j])+1))*nums[i]\n",
    "                # print(ans)\n",
    "            i +=1\n",
    "            j -=1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        l=len(nums)\n",
    "        if l==1:\n",
    "            return nums[0]\n",
    "        for i in range(l//2):\n",
    "            ans+=int(str(nums[i])+str(nums[l-i-1]))\n",
    "        if l%2==0: return ans\n",
    "        else: return ans+nums[l//2]\n",
    "        '''while len(nums)>1:\n",
    "            ans+=int(str(nums[0])+str(nums[len(nums)-1]))\n",
    "            nums.append(0)\n",
    "            nums.append(len(nums)-1)\n",
    "        ans+=nums[0]'''\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        while nums:\n",
    "            if(len(nums)>1):\n",
    "                d=0\n",
    "                while nums[-1]//(10**d)!=0:\n",
    "                    d+=1\n",
    "                ans+=nums[0]*(10**d)+nums[-1]\n",
    "                nums.pop()\n",
    "                nums.pop(0)\n",
    "            else:\n",
    "                ans+=nums[0]\n",
    "                nums.pop()\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        length = len(nums)\n",
    "        ans = 0\n",
    "        for i in range(int(length/2)):\n",
    "            l = nums[i]\n",
    "            r = nums[-(i+1)]\n",
    "            t = int(str(l) +str(r))\n",
    "            ans += t\n",
    "        if length % 2 !=0:\n",
    "            # print(\"odd\")\n",
    "            ans += nums[int(length/2)]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        numsum = []\n",
    "        while len(nums) >= 2:\n",
    "            numssum = str(nums.pop(0))+str(nums.pop(-1))\n",
    "            numsum.append(int(numssum))\n",
    "        if len(nums) % 2 == 0:\n",
    "            return sum(numsum)\n",
    "        else:\n",
    "            numsum += nums\n",
    "            return sum(numsum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        def chuan(left, right):\n",
    "            return (left * (10**(len(str(right)))) + right)\n",
    "\n",
    "        totalchuan = 0\n",
    "        while len(nums) > 1:\n",
    "            left = nums.pop(0)\n",
    "            right = nums.pop()\n",
    "            thischuan = chuan(left,right)\n",
    "            totalchuan += thischuan\n",
    "\n",
    "        if len(nums) == 1:\n",
    "            totalchuan += nums[0]\n",
    "\n",
    "        return totalchuan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        left=0\n",
    "        right=len(nums)-1\n",
    "        ans=0\n",
    "        nums=nums\n",
    "        while left<right:\n",
    "            ans+=int(str(nums[left])+str(nums[right]))\n",
    "            left+=1\n",
    "            right-=1\n",
    "        if left==right:\n",
    "            ans+=nums[left]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        left=0\n",
    "        right=len(nums)-1\n",
    "        ans=0\n",
    "        nums=nums\n",
    "        while left<right:\n",
    "            ans+=int(str(nums[left])+str(nums[right]))\n",
    "            left+=1\n",
    "            right-=1\n",
    "        if left==right:\n",
    "            ans+=nums[left]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        i,j=0,len(nums)-1\n",
    "        re=0\n",
    "        while i<j:\n",
    "            concval=int(str(nums[i])+str(nums[j]))\n",
    "            re+=concval\n",
    "            i+=1\n",
    "            j-=1\n",
    "        if i==j:\n",
    "            re+=nums[i]\n",
    "        else:\n",
    "            pass\n",
    "        return re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        result = 0\n",
    "        i, j = 0, len(nums)-1\n",
    "        while i < j:\n",
    "            result += int(str(nums[i])+str(nums[j]))\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        if i == j:\n",
    "            result += nums[i]\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i <= j:\n",
    "            if i != j:\n",
    "                ans += int(str(nums[i]) + str(nums[j]))\n",
    "            else:\n",
    "                ans += nums[i]\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        a = len(nums)//2\n",
    "        b = sum([int(str(nums[i])+str(nums[i*-1-1])) for i in range(a)])\n",
    "        if len(nums)%2:\n",
    "            b += nums[a]\n",
    "        return b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        i=0\n",
    "        j=len(nums)-1\n",
    "        re=0\n",
    "        while i<j:\n",
    "            concval=int(str(nums[i])+str(nums[j]))\n",
    "            re+=concval\n",
    "            i+=1\n",
    "            j-=1\n",
    "        if i==j:\n",
    "            re+=nums[i]\n",
    "        else:\n",
    "            pass    \n",
    "        \n",
    "        return re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        sum=0\n",
    "        while nums:\n",
    "            n=len(nums)\n",
    "            if n==1:\n",
    "                break\n",
    "            else:\n",
    "                sum+=int(str(nums[0])+str(nums[-1]))\n",
    "                del nums[0]\n",
    "                del nums[-1]\n",
    "        n=len(nums)\n",
    "        if n==1:\n",
    "            sum+=nums[0]\n",
    "            return sum\n",
    "        else:\n",
    "            return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        while len(nums)>1:\n",
    "            ans+=int(str(nums[0])+str(nums[-1]))\n",
    "            nums=nums[1:-1]\n",
    "        print(ans)\n",
    "        if nums:\n",
    "            ans+=int(str(nums[0]))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        s=0\n",
    "        n=len(nums)\n",
    "        for i in range(int(n/2)):\n",
    "            s=s+nums[i]*10**len(str(nums[n-1-i]))+nums[n-1-i]\n",
    "            print(s)\n",
    "        if n%2==0:\n",
    "            return s\n",
    "        else:\n",
    "            return s+nums[int(n/2)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        sum = 0\n",
    "        for i in range(len(nums) // 2):\n",
    "            sum += int(str(nums[i]) + str(nums[len(nums) - i - 1]))\n",
    "        if len(nums) % 2 == 0:\n",
    "            return sum    \n",
    "        else:\n",
    "            return sum + nums[len(nums) // 2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        a=0\n",
    "        if len(nums)%2==0:\n",
    "            for i in range(len(nums)//2):\n",
    "                a+=int(str(nums[i])+str(nums[(i+1)*-1]))\n",
    "        else:\n",
    "            a+=nums[len(nums)//2]\n",
    "            for i in range(len(nums)//2):\n",
    "                a+=int(str(nums[i])+str(nums[(i+1)*-1]))\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        i,j = 0,len(nums)-1\n",
    "        sum = 0\n",
    "        for k in range(len(nums)//2):\n",
    "            sum += int(str(nums[i])+str(nums[j]))\n",
    "            j -= 1\n",
    "            i += 1\n",
    "        if len(nums) % 2 == 0:\n",
    "            return(sum)\n",
    "        else:\n",
    "            return (sum+nums[len(nums)//2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        self=len(nums)\n",
    "        if self==0:\n",
    "            return;\n",
    "        else:\n",
    "            tem1=self%2\n",
    "            con=0\n",
    "            if tem1==0:\n",
    "                for i in range(self//2):\n",
    "                    tem=str(nums[i])+str(nums[self-i-1])\n",
    "                    tem=int(tem)\n",
    "                    con=con+tem\n",
    "                return con;\n",
    "            else:\n",
    "                for i in range(self//2):\n",
    "                    tem=str(nums[i])+str(nums[self-i-1])\n",
    "                    tem=int(tem)\n",
    "                    con=con+tem\n",
    "                    print(con)\n",
    "                return con+nums[self//2];\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        result = 0\n",
    "        for i in range(len(nums)//2):\n",
    "            # print(i, len(nums)-1-i)\n",
    "            result += int(str(nums[i])+str(nums[len(nums)-1-i]))\n",
    "        \n",
    "        if len(nums)%2==1:\n",
    "            result += nums[len(nums)//2]\n",
    "        return result\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        i=0\n",
    "        j=len(nums)-1\n",
    "        re=0\n",
    "        while i<j:\n",
    "            concval=int(str(nums[i])+str(nums[j]))\n",
    "            re+=concval\n",
    "            i+=1\n",
    "            j-=1\n",
    "        if i==j:\n",
    "            re+=nums[i]\n",
    "        else:\n",
    "            pass    \n",
    "        \n",
    "        return re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        result=0\n",
    "        n=len(nums)\n",
    "        i=0\n",
    "        while i*2<n:\n",
    "            if i==n-1-i:\n",
    "                result+=nums[i]\n",
    "            else:\n",
    "                result+=int(str(nums[i])+str(nums[n-1-i]))\n",
    "            i+=1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        left = 0\n",
    "        right = n - 1\n",
    "        res = 0\n",
    "        while left <= right:\n",
    "            res += int(str(nums[left]) + str(nums[right]))\n",
    "            left += 1\n",
    "            right -= 1\n",
    "            if left == right:\n",
    "                res += nums[left]\n",
    "                break\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        l, r = 0, len(nums)-1\n",
    "        ans = 0\n",
    "        while r > l:\n",
    "            ans += nums[l]*10**(len(str(nums[r]))) + nums[r]\n",
    "            r -= 1\n",
    "            l += 1\n",
    "\n",
    "        if r == l:\n",
    "            ans += nums[r]\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        num = 0\n",
    "        i,j = 0,-1\n",
    "        while i < (len(nums)//2):\n",
    "            num += int(str(nums[i])+str(nums[j]))\n",
    "            i+=1\n",
    "            j-=1\n",
    "        if len(nums)%2!=0:\n",
    "            num+=nums[len(nums)//2]\n",
    "        return(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        a=0\n",
    "        i,j=0,len(nums)-1\n",
    "        while i<j:\n",
    "            a=a+nums[j]+nums[i]*10**len(str(nums[j]))\n",
    "            i+=1\n",
    "            j-=1\n",
    "        if i==j:\n",
    "            a+=nums[i]\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        i=0\n",
    "        j=len(nums)-1\n",
    "        re=0\n",
    "        while i<j:\n",
    "            concval=int(str(nums[i])+str(nums[j]))\n",
    "            re+=concval\n",
    "            i+=1\n",
    "            j-=1\n",
    "        if i==j:\n",
    "            re+=nums[i]\n",
    "        else:\n",
    "            pass    \n",
    "        \n",
    "        return re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i < j:\n",
    "            ans += int(str(nums[i]) + str(nums[j]))\n",
    "            i, j = i + 1, j - 1\n",
    "        if i == j:\n",
    "            ans += nums[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        left,right = 0,n-1\n",
    "        s = 0\n",
    "        while left<=right:\n",
    "            if left != right:\n",
    "                s += int(str(nums[left])+str(nums[right]))\n",
    "                left += 1\n",
    "                right -= 1\n",
    "            else:\n",
    "                s += nums[left]\n",
    "                left += 1\n",
    "        return s\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # n = len(nums)\n",
    "        # left,right = 0,n-1\n",
    "        # ans = 0\n",
    "        # while left<=right:\n",
    "        #     if left != right:\n",
    "        #         ans +=int(str(nums[left])+str(nums[right])) \n",
    "        #         left += 1\n",
    "        #         right -= 1\n",
    "        #     else:\n",
    "        #         ans += nums[left]\n",
    "        #         left += 1\n",
    "        #         right -= 1\n",
    "        # return ans \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        result = sum(int(str(nums[i]) + str(nums[n - i - 1])) for i in range(n // 2))\n",
    "        if n % 2 == 1:\n",
    "            result += nums[n // 2]\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        i=0\n",
    "        j=len(nums)-1\n",
    "        re=0\n",
    "        while i<j:\n",
    "            concval=int(str(nums[i])+str(nums[j]))\n",
    "            re+=concval\n",
    "            i+=1\n",
    "            j-=1\n",
    "        if i==j:\n",
    "            re+=nums[i]\n",
    "        else:\n",
    "            pass    \n",
    "        \n",
    "        return re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for i in range(len(nums)):\n",
    "            nums[i] = str(nums[i])\n",
    "        while len(nums) != 0 and len(nums) != 1:\n",
    "            ans = ans +  int(nums[0] + nums[-1])\n",
    "            nums.pop(0)\n",
    "            nums.pop(-1)\n",
    "        if len(nums) == 1:\n",
    "            ans = ans + int(nums[0])\n",
    "        return int(ans)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findTheArrayConcVal(self, nums: List[int]) -> int:\n",
    "        s=0\n",
    "        while len(nums)!=0:\n",
    "            if len(nums)>1:\n",
    "                first = nums.pop(0)\n",
    "                end = nums.pop()\n",
    "                s += int(str(first)+str(end))\n",
    "            else:\n",
    "                s+= nums.pop()\n",
    "        return(s)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
